package packet1;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int num[] = new int[n];
        //sc.nextLine();
        for(int i = 0; i < n; i++)
        {
            num[i] = sc.nextInt();
        }
        //sc.nextLine();
        int ask[][] = new int[m][3];
        for(int i = 0; i < m; i++){
            for (int j = 0; j < 3; j++) {
                ask[i][j] = sc.nextInt();
            }
        }
        sc.nextLine();
        for(int i = 0; i < m; i++){
            int tol = 0;
            for (int j = ask[i][0]; j <= ask[i][1]; j++) {
                boolean re = valid(num[j - 1], ask[i][2]);
                if(re)
                    tol++;
            }
            System.out.println(tol);
        }
    }
    public static boolean valid(int i, int j){
        if(i == 0 || j == 0)
        return true;

        if(i % j == 0)
            return false;
        else
        return valid(j, i % j);
    }
}
